package com.sinping.qh.query.base;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;

/**
 * @author wupeng
 * @create 2018/6/5
 */
public final class AggregateParams implements Serializable {
    private static final long serialVersionUID = 7581303197853784555L;

    Map<String, String> aliasMap = new HashMap<>();
    Map<String, AggregateOperator> operatorMap = new HashMap<>();

    public void add(String fieldName, String alias, AggregateOperator operator) {
        aliasMap.put(fieldName, alias);
        operatorMap.put(fieldName, operator);
    }

    public void add(String fieldName, String alias) {
        aliasMap.put(fieldName, alias);
        operatorMap.put(fieldName, AggregateOperator.count);
    }

    public String getAlias(String fieldName) {
        return aliasMap.getOrDefault(fieldName, fieldName);
    }

    public AggregateOperator getAggregateOperator(String fieldName) {
        return operatorMap.getOrDefault(fieldName, AggregateOperator.count);
    }

    public Set<String> getFieldNames() {
        return aliasMap.keySet();
    }

}
